<template>
    <div class="reset">
        <div class="go_back" @click="back"></div>
        <div class="reg_all">
            <div class="oldpassword">
                <input type="password" v-model.trim="oldpassword" class="reg_inp" v-on:input="canon" placeholder="请输入旧密码" maxlength="12">
            </div>    
            <div class="password">
                <input :type="inputType" v-model.trim="newpassword" class="reg_inp" v-on:input="canon" placeholder="请输入新密码" maxlength="12">
                <div :class="eye?'see':'eye'" @click="showPass"></div>
            </div>
            <div class="reg_div">
                <input type="button" :class="rule?'reg_true':'reg_btn'" value="确认"  :disabled="!rule"  @click="sure"> 
            </div>
        </div>    
    </div>    
</template>
<script>
    export default {
        name: 'Reset',
        data () {
             return {
                rule:false, 
                eye:true,
                oldpassword:'',
                newpassword:'',
                inputType:'password', 
                rule:false,
                token:"",
             }
        },
        created(){
            document.title="重置密码";
            if (localStorage.token) {
                this.token=localStorage.getItem('token');
            }else{
               this.$router.push({path:'/login'}); 
            }
        },
        methods:{
            back(){
                this.$router.go(-1);
            },
            showPass(){
                this.eye=!this.eye;
                if (this.eye) {
                    this.inputType = 'password'
                } else {
                    this.inputType = 'text'
                }
            },
            canon(){
                if(this.oldpassword.length>=6&&this.newpassword.length>=6){
                    this.rule=true;
                }else{
                    this.rule=false;
                }
            },
            sure(){
                var params = new URLSearchParams();
                params.append('password_new',this.newpassword);       //你要传给后台的参数值 key/value
                params.append('password_old',this.oldpassword);
                this.$axios({
					url:'/v1/user/resetPassword',
                    method: 'post',
                    data:params,
					headers:{
					  'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8',
                      'Authorization':"bearer "+this.token
					}
				})
				.then(respanse=>{
                    var res=respanse.data;
                    if(res.code==200){
                        Toast("修改成功！")
                        this.$router.push({path:'/set'});
                    }else if(res.data.code==1000){
                         Toast(res.data.msg);
                         this.$router.push({path:'/login'});
                    }else{
                        Toast(res.msg)
                    }
                    
				})
            },
        }
    }
</script>
<style scoped>
.reg_all{width:698px;margin:0 auto;}
.go_back{width:48px;height:48px;background:url("/static/images/team_go_back.png") no-repeat center center;background-size:100% 100%;margin-top:20px;margin-left:12px;}
.reg_inp{border:none;width:100%;height:104px;border-bottom:2px solid #ECECEC;font-size:32px;}
.reg_btn{width:100%;height:98px;line-height:100px;border-radius:50px;text-align:center;font-size:32px;color:#4A4A4A;background:#ECECEC;margin-top:70px;cursor:pointer;outline:0px; -webkit-appearance:none;border:none;}
.reg_true{width:100%;height:98px;line-height:100px;border-radius:50px;text-align:center;font-size:32px;color:#333334;background:#FFE514;margin-top:70px;cursor:pointer;outline:0px; -webkit-appearance:none;border:none;}
.password{position: relative;}
.see{width:48px;height:48px;background:url("/static/images/see.png") no-repeat center center;background-size:100% 100%;position: absolute;right:0;top:34px;}
.eye{width:48px;height:48px;background:url("/static/images/eye.png") no-repeat center center;background-size:100% 100%;position: absolute;right:0;top:34px;}
</style>